home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / AFPFM / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-26  |  3.1 KB  |  180 lines  |  [TEXT/KAHL]

  1. #include <stdio.h>
  2. #include "ICAPI.h"
  3. #include "ICKeys.h"
  4.  
  5. void InitToolbox(void);
  6.  
  7. void InitToolbox()
  8. {
  9.     InitGraf((Ptr) &qd.thePort);
  10.     InitFonts();
  11.     InitWindows();
  12.     InitMenus();
  13.     FlushEvents(everyEvent,0);
  14.     TEInit();
  15.     InitDialogs(0L);
  16.     InitCursor();
  17. }
  18.  
  19. /******************************************************************************
  20.  *
  21.  * Internet Config stuff
  22.  *
  23.  * Get Internet Config Prefs
  24.  */
  25. Boolean InitICMappings( ICInstance *inst, Handle *ICmappings )
  26. {
  27.     Boolean ICErr = true;
  28.         
  29.     if ( *ICmappings != nil )
  30.         return ICErr;
  31.         
  32.     if (!ICStart(inst, '????'))
  33.     {                                                // init the sucker
  34.         if (!ICFindConfigFile(*inst, 0, nil))
  35.         {                                            // locate the config file
  36.             if (!ICBegin(*inst, icReadOnlyPerm))
  37.             {                                        // open up the file for reading
  38.                 ICAttr    attr = 0;
  39.  
  40.                 ICErr = false;
  41.                     
  42.                 if (!ICGetPrefHandle(*inst, (ConstStr255Param)kICMapping, &attr, ICmappings))
  43.                 {
  44.                         HUnlock(*ICmappings);
  45.                 }
  46.                 else
  47.                 {
  48.                     /* Can't get ICmappings */
  49.                     ICErr = true;
  50.                 }
  51.                 ICEnd(*inst);                            // all done
  52.             }
  53.         }
  54.     }
  55.         
  56.     if((ICErr)&&(*ICmappings != nil))
  57.     {
  58.         DisposeHandle(*ICmappings);
  59.         *ICmappings = nil;
  60.         
  61.         ICStop(*inst);
  62.     }
  63.     
  64.     return ICErr;
  65. }
  66.  
  67. void DisposeICMappings( ICInstance *inst, Handle *ICmappings )
  68. {
  69.     if(*ICmappings != nil)
  70.     {
  71.         DisposeHandle(*ICmappings);
  72.         *ICmappings = nil;
  73.         
  74.         ICStop(*inst);
  75.     }
  76. }
  77.  
  78. /******************************************************************************
  79.  *
  80.  * main
  81.  *
  82.  */
  83.  
  84. main()
  85. {
  86.     OSErr        oserr;
  87.     ICInstance    ICinst;
  88.     Handle        ICmappings = nil;
  89.     OSType        Type;
  90.     OSType        Creator;
  91.     char        Description[256];
  92.     short        Binary;
  93.     short        MacFile;
  94.     long         pos = 0;
  95.     ICMapEntry    entry;
  96.     StandardFileReply    reply;
  97.     short        r;
  98.     long        i;
  99.     Handle        header;
  100.     
  101.     
  102.     InitToolbox();
  103.     
  104.     
  105.     if (noErr == InitICMappings( &ICinst, &ICmappings ))
  106.     {
  107.         StandardPutFile("\pSave as…","\pafpfile", &reply);
  108.         if ( reply.sfGood )
  109.         {
  110.             if ( reply.sfReplacing )
  111.                 FSDelete( reply.sfFile.name, reply.sfFile.vRefNum );
  112.                 
  113.             FSpCreate( &reply.sfFile, 'ttxt', 'TEXT', reply.sfScript);
  114.             FSpOpenDF( &reply.sfFile, fsCurPerm, &r );
  115.             
  116.             if ( nil != (header = GetResource('TEXT', 128)))
  117.             {
  118.                 i=GetHandleSize(header);
  119.                 
  120.                 FSWrite(r,&i, *header);
  121.                 ReleaseResource(header);
  122.             }
  123.         while ( noErr == ( oserr = ICGetMapEntry( ICinst, ICmappings, pos, &entry)))
  124.         {
  125.             pos += entry.total_length;
  126.             
  127.             if ( 0!= (i = (long)entry.extension[0]))
  128.             {
  129.             FSWrite(r, &i, &entry.extension[1]);
  130.             
  131.             if (entry.flags & ICmap_binary_mask)
  132.             {
  133.                 i = 4;
  134.                 FSWrite(r, &i, "\tRaw");
  135.             }
  136.             else
  137.             {
  138.                 i = 6;
  139.                 FSWrite(r, &i, "\tAscii");
  140.             }
  141.             
  142.             i = 2;
  143.             FSWrite(r, &i, "\t'");
  144.             
  145.             i = sizeof (OSType );
  146.             FSWrite(r, &i, &entry.file_creator);
  147.  
  148.  
  149.             i = 3;
  150.             FSWrite(r, &i, "'\t'");
  151.             
  152.             i = sizeof (OSType );
  153.             FSWrite(r, &i, &entry.file_type);
  154.             
  155.             i = 3;
  156.             FSWrite(r, &i, "'\t\"");
  157.             i = (long)entry.entry_name[0];
  158.             FSWrite(r, &i, &entry.entry_name[1]);
  159.             
  160.  
  161.             i = 2;
  162.             FSWrite(r, &i, "\"\r");
  163.             }
  164.                         
  165.         }
  166.             if ( nil != (header = GetResource('TEXT', 129)))
  167.             {
  168.                 i=GetHandleSize(header);
  169.                 
  170.                 FSWrite(r,&i, *header);
  171.                 ReleaseResource(header);
  172.             }
  173.  
  174.             FSClose( r );
  175.         }
  176.         DisposeICMappings( &ICinst, &ICmappings );
  177.     }
  178. }
  179.  
  180.